package com.hdax.dm.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.entity.order.Order;
import com.hdax.dm.order.dto.OrderDto;
import com.hdax.dm.order.mappers.OrderDtoMapper;
import com.hdax.dm.order.mappers.OrderMapper;
import com.hdax.dm.order.service.OrderDtoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderDtoServiceImpl extends ServiceImpl<OrderDtoMapper, OrderDto> implements OrderDtoService {

    @Autowired
    private OrderMapper orderMapper;
    @Override
    public OrderDto selectByUser(Long orderId) {
        OrderDto orderDto=new OrderDto();
        QueryWrapper<Order> orderQueryWrapper=new QueryWrapper<>();
        orderQueryWrapper.eq("orderNo",orderId);//订单编号
        Order order=orderMapper.selectOne(orderQueryWrapper);
        orderDto.setItemName(order.getItemName());//商品名称

        Long orderno= Long.valueOf(order.getOrderNo());
        Double yingfu= Double.valueOf(order.getTotalAmount());
        orderDto.setOrderNo(orderno);//订单号
        System.out.println(yingfu);
        System.out.println(order.getTotalAmount());
        System.out.println(order.getIsNeedInsurance());
        if (order.getIsNeedInsurance()==null){
            orderDto.setPayAmountt(yingfu);//应付金额
            orderDto.setTotalAmount(order.getTotalAmount());//订单金额
        }else{
            orderDto.setPayAmountt(yingfu);//应付金额
            orderDto.setTotalAmount(order.getTotalAmount()-20L);//订单金额
        }
        return orderDto;
    }
}

